package cn.tedu.springmvc.controller;

import cn.tedu.springmvc.mapper.UserInfoMapper;
import cn.tedu.springmvc.pojo.dto.UserDTO;
import cn.tedu.springmvc.pojo.entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
    /*
    @RequestMapping("/regUser")//请求
    @ResponseBody//响应
    public String regUser(HttpServletRequest request){
        System.out.println("开始处理用户注册!!!!");
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String nickname = request.getParameter("nickname");
        String age = request.getParameter("age");
        System.out.println(username+","+password+","+nickname+","+age);
        return "注册成功!" ;}
     */
    /*
    @RequestMapping("/regUser")
    @ResponseBody
    public String regUser(String username,String password,String nickname,int age){
        System.out.println("开始处理注册");
        System.out.println(username+","+password+","+nickname+","+age);
        return "注册成功";
    }*/
    @Autowired
    private UserInfoMapper userInfoMapper;
    @RequestMapping("/regUser")
    @ResponseBody
    public String regUser(UserDTO userDTO){
        System.out.println(userDTO);
        UserInfo userInfo = new UserInfo();
        userInfo.setUsername(userDTO.getUsername());
        userInfo.setPassword(userDTO.getPassword());
        userInfo.setNickname(userDTO.getNickname());
        userInfo.setAge(userDTO.getAge());
        int num = userInfoMapper.insertUserInfo(userInfo);
        return num>0?"注册成功":"注册失败";
    }


}
